package com.apesay.plugins;


import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

/**
 * ClassName:UserVisitor
 * Reason:	 
 * Date:     2017/11/10 11:33
 *
 * @author sid
 */
public class UserVisitor extends ClassVisitor {

    public UserVisitor(int api) {
        super(api);
    }
    public UserVisitor(final ClassVisitor cv) {
        super(Opcodes.ASM6,cv);
    }
    public UserVisitor(int api,final ClassVisitor cv) {
        super(api,cv);
    }

    @Override
    public void visitEnd() {
//        System.out.println("UserVisitor.visitEnd");
        super.visitEnd();
    }

    @Override
    public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
//        System.out.println("UserVisitor.visit");
        super.visit(version, access, name, signature, superName, interfaces);
    }

    @Override
    public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
        MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
        // 对isAdult方法进行处理
        if (MethodHandlePlugin3.methodName.equals(name)) {
            mv = new UserMethodVisitor(this.api, mv);
            return mv;
//            return super.visitMethod(access, name + "$1", desc, signature, exceptions);
        }
        return mv;
    }
}
